Global Variables. ˆ Unlike local variables, global variables are available to all functions involved.

Size: px
Start display at page:

Download "Global Variables. ˆ Unlike local variables, global variables are available to all functions involved."

Transcription

1 Global Variables ˆ Unlike local variables, global variables are available to all functions involved. ˆ Use global to declare x as global. ˆ For example, the universal constant, say,. 1 ˆ However, it is not a good practice to define many global variables. 2 ˆ Besides, you have to take the responsibility of not changing its value. 1 Planck constant = in quantum theories. 2 This violets the principle of modularity. Zheng-Liang Lu 192 / 236

2 Example 1 function h = freefall(t) 2 global GRAVITY 3 h = 1 / 2 * GRAVITY * t.ˆ 2; 4 end 1 clear; clc; 2 global GRAVITY 3 GRAVITY = 9.8; 4 y = freefall(0 : 0.1 : 5); ˆ As a more robust alternative, redefine this function to accept GRAVITY as an input. Zheng-Liang Lu 193 / 236

3 Relationships among User-Defined Functions ˆ Primary functions and subfunctions ˆ Anonymous functions ˆ Nested functions ˆ Private functions Zheng-Liang Lu 194 / 236

4 Primary Functions and Subfunctions ˆ An m-file may contain more than one user-defined function. ˆ The function whose name is identical to the file name is called the primary function, while the other functions are called subfunctions. ˆ Subfunctions are normally visible only to the primary function and other subfunctions. 3 ˆ Note that the order of the subfunctions does not matter, but function names must be unique within the m-file. 3 This is an implementation of namespaces which avoid name collisions between multiple identifiers that share the same name. Zheng-Liang Lu 195 / 236

5 Example: Alternative to Infinite Loops 4 1 function test1 2 fprintf('hi, there. This is test1.\n'); 3 test2; 4 end 5 6 function test2 7 fprintf('hi, there. This is test2.\n'); 8 test1; 9 end ˆ Notice that the aforesaid program becomes an infinite loop and is terminated by Matlab since the depth of call stack is limited. 4 Thanks to a lively class discussion (MATLAB238) on June 14, Zheng-Liang Lu 196 / 236

6 Handling Anonymous Functions 6 ˆ You can use function handles for anonymous functions, which are the expression followed by operator. 5 ˆ This enables you to create a simple function without creating an m-file for it. ˆ For example, 1 >> f x.ˆ 2 + x + 1 % x.ˆ2 allows... vectorization. 2 >> f([1 10]) 3 4 ans = See 6 See anonymous-functions.html. Zheng-Liang Lu 197 / 236

7 ˆ Furthermore, you can assign an existing function to a function handle, for example, y 7 ˆ You can create anonymous functions having more than one input. ˆ One anonymous function can call another to implement function composition. 1 >> f y) sqrt(x.ˆ 2 + y.ˆ 2); 2 >> g y) f(x, y).ˆ 2; 3 >> g(3, 4) 4 5 ans = You may refer to The truth is that every function name is also an alias of the function address! Zheng-Liang Lu 198 / 236

8 More Examples 9 ˆ Given input values, return a function handle. 8 ˆ For example, 1 function y = paragen(a, b, c) 2 y a * x.ˆ 2 + b * x + c; 3 end ˆ Acts like a parabolic function generator! 8 Contribution by Ms. Queenie Chang (MAT25108) on March 18, Thanks to a lively class discussion (MATLAB244) on August 22, Zheng-Liang Lu 199 / 236

9 ˆ Given a function handle as an input, return a value. 10 ˆ For example, 1 function y = df(f, x) 2 eps = 1e-9; 3 y = (f(x + eps) - f(x)) / eps; 4 end ˆ Given a function handle as an input, return a function handle. ˆ For example, 1 function y = df(f) 2 eps = 1e-9; 3 y (f(x + eps) - f(x)) / eps; 4 end 10 Thanks to a lively class discussion (MATLAB260) on September 16, Zheng-Liang Lu 200 / 236

10 Nested Functions ˆ A function is said to be nested if the function is defined within another function. ˆ A nested function can access the variables of its parent function. 1 function f = paragen(a, b, c) 2 f %f is a function handle of p 3 function y = p(x) 4 % p shares a, b, and c with parabola 5 y = a * x.ˆ2 + b * x + c; 6 end 7 end Zheng-Liang Lu 201 / 236

11 Private Functions ˆ Private functions are useful when you want to limit the scope of the functions. ˆ A private functions resides in a subfolder with the special name private. ˆ The private function is visible only to functions in its parent directory. ˆ Note that you cannot call the private function from the command line or from functions outside the parent folder of the private. Zheng-Liang Lu 202 / 236

12 Precedence When Calling Functions 1. Nested functions 2. Subfunctions within the same file 3. Private functions 4. Local functions in the same directory 5. Built-in functions 6. Standard m files in PATH Zheng-Liang Lu 203 / 236

13 Recursive Functions ˆ Recursion is when something is defined in terms of itself. ˆ A recursive function is the function which calls itself. ˆ Recursion is an alternative form of program control. ˆ It is essentially repetition without a loop. Zheng-Liang Lu 204 / 236

14 Example ˆ The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. ˆ For example, 4! = = 4 3! ˆ So we can say f (n) = n f (n 1), for n > 0. ˆ Also, we need a base case such that the recursion can stop instead of being an infinite loop. ˆ In this example, 0! = 1. Zheng-Liang Lu 205 / 236

15 Exercise Write a program which determines return a factorial of n. 1 function y = recursivefactorial(n) 2 if n > 0 3 y = n * recursivefactorial(n - 1); 4 else 5 y = 1; % base case 6 end 7 end ˆ We can use a loop to calculate n!. (Try.) Zheng-Liang Lu 206 / 236

16 Call Stack Zheng-Liang Lu 207 / 236

17 Equivalence 1 function y = loopfactorial(n) 2 y = 1; 3 for i = n : -1 : 2 4 y = y * i; 5 end 6 end ˆ One more intriguing question is, Can we always turn a recursive method into an iterative one? ˆ Yes, theoretically. 11 ˆ Which is better? 11 The Church-Turing thesis proves it if the memory serves. Zheng-Liang Lu 208 / 236

18 Example: Fibonacci Numbers 12 ˆ The Fibonacci sequence is as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, ˆ Equivalently, the Fibonacci sequence follows the recurrence relation F n = F n 1 + F n 2, where n 2, and F 0 = 0, F 1 = 1. ˆ Given integer n 0, determine F n. 12 See Fibonacci numbers. Zheng-Liang Lu 209 / 236

19 Solution 1 function y = recurfib(n) 2 if n == 0 3 y = 0; 4 elseif n == 1 5 y = 1; 6 else 7 y = recurfib(n - 1) + recurfib(n - 2); 8 end 9 end ˆ It is a binary recursion because this function calls itself twice. ˆ Time complexity: O(2 n ) (Why?) Zheng-Liang Lu 210 / 236

20 Fibonacci Numbers by Loops 1 function y = loopfib(n) 2 if n == 0 3 y = 0; 4 elseif n == 1 5 y = 1; 6 else 7 x = 0; 8 y = 1; 9 for i = 2 : n 10 tmp = x + y; 11 x = y; 12 y = tmp; 13 end 14 end 15 end ˆ Can we implement a linear recursion for this problem? Zheng-Liang Lu 211 / 236

21 Fibonacci Numbers by Linear Recursion 1 function ret = linearfib(n) 2 ret = fib(0, 1, n); 3 function c = fib(a, b, n) % nested function 4 if n > 0 5 c = fib(b, b + a, n - 1); 6 else 7 c = a; 8 end 9 end 10 end ˆ Time complexity: O(n)! Zheng-Liang Lu 212 / 236

22 Remarks ˆ Recursion bears substantial overhead. ˆ So the recursive algorithm may execute a bit more slowly than the iterative equivalent. 13 ˆ Moreover, a deeply recursive method depletes the call stack, which is limited, and causes a exception fast In modern compiler design, recursion elimination is automatic if the recurrence occurs in the last statement in the recursive function, so called tail recursion. However, only some of programming languages support the elimination of tail recursion. Unfortunately, Matlab does not support it. 14 Aka stack overflow. Zheng-Liang Lu 213 / 236

23 More Interesting Recursions ˆ Sum of numbers ˆ Product of numbers ˆ Greatest common divisor ˆ Towers of Hanoi ˆ Check whether a string is palindrome 15 using recursion ˆ N-Queens problem ˆ Quick sqrt ˆ Depth-first search ˆ Reversing a string ˆ Computing n mod m without using the function mod() 15 For example, noon, level, and radar. Zheng-Liang Lu 214 / 236

24 1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 215 / 236

25 Introduction ˆ Engineers use graphic techniques to make the information easier to understand. ˆ With graphs, it is easy to identify trends, pick out highs and lows, and isolate data points that may be measurement or calculation errors. ˆ Graphs can also be used as a quick check to determine whether a computer solution is yielding expected results. ˆ A set of ordered pairs is used to identify points on a two-dimensional graph. ˆ The data points are then connected by straight lines in common cases. Zheng-Liang Lu 216 / 236

26 2D Line Plot ˆ The function plot(x, y, CLM ) creates a 2-D line plot of the data in y versus the corresponding values in x. ˆ (x, y): data set, ˆ C: specify the color, ˆ L: specify the line type, ˆ M: specify the data marker. ˆ A figure is created automatically as soon as the function plot is called. Zheng-Liang Lu 217 / 236

27 Optional Parameters for CLM 16 ˆ Try help for further details about plot. 16 See Zheng-Liang Lu 218 / 236

28 Example 1 clear; clc; close all; 2 3 x = 0 : 0.1 : 2 * pi; 4 y = sin(x); 5 figure(1); % create Figure 1 6 plot(x, y, 'r-'); % plot a red and solid line 7 grid on; % show the grid ˆ Note that you can simply call figure without specifying a number. ˆ Use close to close all figures or specific one. ˆ You can try clf and cla. Zheng-Liang Lu 219 / 236

29 Zheng-Liang Lu 220 / 236

30 Example 2: Multiple Curves 1 clear; clc; 2 x = linspace(0, 2 * pi, 100); 3 figure(2); % create Figure 2 4 plot(x, sin(x), '*', x, cos(x), 'o', x, sin(x) +... cos(x), '+'); 5 grid on; ˆ You can also use plot(x, A), where A is an m-by-n matrix and x is an array of size n, draws a figure for m lines. (Try.) Zheng-Liang Lu 221 / 236

31 Zheng-Liang Lu 222 / 236

32 Exercise ˆ Plot sin(x), x 2, log 10 (x), and 2 x where x [0, 1] with 100 points in a single figure. 1 clear; clc; close all; 2 3 x = linspace(0, 1, 100); 4 y = [sin(x); x.ˆ 2; log10(x); 2.ˆ x]; 5 C = 'rgbc'; 6 M = '.od+'; 7 L = {'-', '-.', ':', '--'}; 8 figure; hold on; grid on; 9 for i = 1 : size(y, 1); 10 plot(x, y(i,:), [C(i) M(i) L{i}]); 11 end Zheng-Liang Lu 223 / 236

33 Zheng-Liang Lu 224 / 236

34 Annotating Plots ˆ title( string ) adds a title to the plot. ˆ xlabel( string ) adds a label to the x axis of the plot. ˆ ylabel( string ) adds a label to the y axis of the plot. ˆ legend({ string1, string2,...}) allows you to add a legend for the multiple lines. ˆ The legend shows a sample of the line and lists the string you have specified. ˆ text(x, y, string ) allows you to add a text box for the string and located at (x, y) in the figure. ˆ gtext is similar to text. ˆ The box is placed at a location determined interactively by the user by clicking in the figure window. Zheng-Liang Lu 225 / 236

35 Example 1 clear; clc; 2 3 x = linspace(0, 1, 100); 4 y = [sin(x); x.ˆ 2; log10(x); 2.ˆ x]; 5 color = 'rgbk'; 6 figure(1); hold on; grid on; 7 for i = 1 : 4 8 plot(x, y(i, :), [color(i) 'o:']); 9 end 10 title('demonstration'); 11 xlabel('time (Year)'); 12 ylabel('this is Y label. (Unit)'); 13 legend({'curve A', 'xˆ{2}', 'log {10}(x)',... 'eˆ{x}'}, 'Interpreter', 'tex'); 14 text(0.4, -1.5, 'This is a text.'); 15 gtext('matlab supports the LaTex symbols.'); Zheng-Liang Lu 226 / 236

36 Demonstration Curve A x 2 log 10 (x) e x This is Y label. (Unit) Matlab supports the LaTex symbols. 1.5 This is a text Time (Year) Zheng-Liang Lu 227 / 236

37 L A TEX ˆ TEX is a technical typesetting language, created by Donald Knuth, which is widely used for formatting mathematical expressions. ˆ L A TEXis a set of macros created by Leslie Lamport, which expand the power of TEX and made it easier to use. ˆ By default, several Matlab text-related commands, including xlabel, ylabel, title, and text, automatically interpret a subset of TEX commands. ˆ See and for further information. Zheng-Liang Lu 228 / 236

38 Greek Symbols 17 ˆ Replace the first letter by the upper case one in the L A TEXcode for the upper case Greek letters. ˆ For example, use \Omega for Ω. 17 See Table B.1 in Lent, p Zheng-Liang Lu 229 / 236

39 Binary Operators See Table B.3 in Lent, p Zheng-Liang Lu 230 / 236

40 Example: Use L A TEX 1 clf 2 axis([ ]); 3 title('testing Latex Math:... $\sqrt{1 - \chi(x) ˆ2}$',... 4 'Interpreter','latex') 5 text(0.2,0.25,'$$ \int 0ˆ\infty f(x) dx $$',... 6 'Interpreter','latex','FontSize',14); 7 text(0.2,0.45,'$$ \sum {k=0}ˆn \frac{1}{kˆn} $$',... 8 'Interpreter','latex','FontSize',14); 9 text(0.2,0.65,'$$ \left(\frac{1}{a}... \right)ˆ{2k+1} $$', 'Interpreter','latex','FontSize',14); 11 text(0.2,0.80,'$ \sum {k=0}ˆn \frac{1}{kˆn} $', 'Interpreter','latex','FontSize',14); 13 text(0.6,0.80,'$ \frac{dˆ2y}{dxˆ2} $', 'Interpreter','latex','FontSize',14); 15 text(0.6,0.65,'$$ \frac{dˆ2y}{dxˆ2} $$',... Zheng-Liang Lu 231 / 236

41 16 'Interpreter','latex','FontSize',14); 17 text(0.6,0.45,'$$ \frac{-b\pm\sqrt{bˆ2-4ac}}{2a}... $$', 'Interpreter','latex','FontSize',14); 19 text(0.6,0.25,'$$ \frac{1-\beta}{1+\alpha} $$', 'Interpreter','latex','FontSize',14); 21 text(0.4,0.9,'$$ $$', 'Interpreter','latex','FontSize',14); 23 xlabel('\alpha 1ˆ2'); 24 ylabel('$$\frac{1-x}{1+x}$$','interpreter','latex'); Zheng-Liang Lu 232 / 236

42 1 Testing Latex Math: 1 χ(x) 2 1 x 1+x N k=0 1 k n ( ) 2k+1 1 a N k=0 0 1 k n f(x)dx d 2 y dx 2 d 2 y dx 2 b± b 2 4ac 2a 1 β 1 +α α 1 Zheng-Liang Lu 233 / 236

43 Exercise: Black-Scholes Model 19 ˆ The Black-Scholes model is one of the most famous models for derivatives. ˆ In this model, a geometric Brownian motion is used to model the price dynamic of the underlying asset, given by ds t = rsdt + σs t dw t, where r is the risk-free interest rate, σ is the annualized volatility, and dw is also called Wiener process, following the standard normal distribution. ˆ We can approximate ds by calculating S i S i 1 where i is the time step. ˆ This numerical scheme is called finite difference. 19 Black and Scholes (1972). Zheng-Liang Lu 234 / 236

44 1 clear; clc; 2 3 N = 252; % 252 trading days typically 4 r = 0.01; % annual risk-free interest rate 5 vol = 0.3; % annual volatility 6 dt = 1 / N; 7 S = zeros(1, N + 1); 8 S(1) = 100; 9 10 for i = 2 : N ds = S(i - 1) * (r * dt + vol * sqrt(dt) *... randn(1)); 12 S(i) = S(i - 1) + ds; 13 end figure; plot(1 : N, S, '.:'); grid on; 16 ylabel('stock Price (TWD)'); 17 xlabel('trading Day (Day)'); Zheng-Liang Lu 235 / 236

45 110 MATLAB Stock Price (TWD) Trading Day (Day) Zheng-Liang Lu 236 / 236

Scope of Variables. In general, it is not a good practice to define many global variables. 1. Use global to declare x as a global variable.

Scope of Variables. In general, it is not a good practice to define many global variables. 1. Use global to declare x as a global variable. Scope of Variables The variables used in function m-files are known as local variables. Any variable defined within the function exists only for the function to use. The only way a function can communicate

More information

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225 1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225 Functions The first thing of the design of algorithms is to divide and conquer. A large and complex problem would be solved by couples

More information

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 Functions Recall that an algorithm is a feasible solution to the specific problem. 1 A function is a piece of computer code that accepts

More information

1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243

1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243 1 >> Lecture 4 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 43 Introduction ˆ Engineers use graphic techniques to make the information easier to understand. ˆ With graphs, it is easy to identify trends,

More information

The return Statement

The return Statement The return Statement The return statement is the end point of the method. A callee is a method invoked by a caller. The callee returns to the caller if the callee completes all the statements (w/o a return

More information

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226 Method Invocation Note that the input parameters are sort of variables declared within the method as placeholders. When calling the method, one needs to provide arguments, which must match the parameters

More information

Variable Scope. The variable scope is the range of the program where the variable can be referenced.

Variable Scope. The variable scope is the range of the program where the variable can be referenced. Variable Scope The variable scope is the range of the program where the variable can be referenced. Variables can be declared in class level, method level, and loop level. In general, a pair of curly brackets

More information

Exercise. Write a program which allows the user to enter the math grades one by one (-1 to exit), and outputs a histogram.

Exercise. Write a program which allows the user to enter the math grades one by one (-1 to exit), and outputs a histogram. Exercise Write a program which allows the user to enter the math grades one by one (-1 to exit), and outputs a histogram. Zheng-Liang Lu Java Programming 197 / 227 1... 2 int[] hist = new int[5]; 3 //

More information

Cloning Arrays. In practice, one might duplicate an array for some reason. One could attempt to use the assignment statement (=), for example,

Cloning Arrays. In practice, one might duplicate an array for some reason. One could attempt to use the assignment statement (=), for example, Cloning Arrays In practice, one might duplicate an array for some reason. One could attempt to use the assignment statement (=), for example, 1... 2 T[] A = {...}; // assume A is an array 3 T[] B = A;

More information

Recursion 1. Recursion is the process of defining something in terms of itself.

Recursion 1. Recursion is the process of defining something in terms of itself. Recursion 1 Recursion is the process of defining something in terms of itself. A method that calls itself is said to be recursive. Recursion is an alternative form of program control. It is repetition

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

1 class Lecture4 { 2 3 "Loops" / References 8 [1] Ch. 5 in YDL 9 / Zheng-Liang Lu Java Programming 125 / 207

1 class Lecture4 { 2 3 Loops / References 8 [1] Ch. 5 in YDL 9 / Zheng-Liang Lu Java Programming 125 / 207 1 class Lecture4 { 2 3 "Loops" 4 5 } 6 7 / References 8 [1] Ch. 5 in YDL 9 / Zheng-Liang Lu Java Programming 125 / 207 Loops A loop can be used to make a program execute statements repeatedly without having

More information

Basic Graphs. Dmitry Adamskiy 16 November 2011

Basic Graphs. Dmitry Adamskiy 16 November 2011 Basic Graphs Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 16 November 211 1 Plot Function plot(x,y): plots vector Y versus vector X X and Y must have the same size: X = [x1, x2 xn] and Y = [y1, y2,, yn] Broken

More information

Computational Finance

Computational Finance Computational Finance Introduction to Matlab Marek Kolman Matlab program/programming language for technical computing particularly for numerical issues works on matrix/vector basis usually used for functional

More information

MATLAB SUMMARY FOR MATH2070/2970

MATLAB SUMMARY FOR MATH2070/2970 MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 310 Advanced Data Structures and Algorithms Recursion June 27, 2017 Tong Wang UMass Boston CS 310 June 27, 2017 1 / 20 Recursion Recursion means defining something, such as a function, in terms of itself

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

Java Programming. U Hou Lok. Java Aug., Department of Computer Science and Information Engineering, National Taiwan University

Java Programming. U Hou Lok. Java Aug., Department of Computer Science and Information Engineering, National Taiwan University Java Programming U Hou Lok Department of Computer Science and Information Engineering, National Taiwan University Java 272 8 19 Aug., 2016 U Hou Lok Java Programming 1 / 51 A Math Toolbox: Math Class The

More information

Mini-Project System Simulation over AWGN Using BPSK Modulation

Mini-Project System Simulation over AWGN Using BPSK Modulation Mini-Project System Simulation over AWGN Using BPSK Modulation Part I: MATLAB Environment Due Date: June 5, 2006. This exercise will guide you to realize the basic operating environment. Some useful instructions

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

q To develop recursive methods for recursive mathematical functions ( ).

q To develop recursive methods for recursive mathematical functions ( ). Chapter 8 Recursion CS: Java Programming Colorado State University Motivations Suppose you want to find all the files under a directory that contains a particular word. How do you solve this problem? There

More information

q To develop recursive methods for recursive mathematical functions ( ).

q To develop recursive methods for recursive mathematical functions ( ). /2/8 Chapter 8 Recursion CS: Java Programming Colorado State University Motivations Suppose you want to find all the files under a directory that contains a particular word. How do you solve this problem?

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab The purpose of this intro is to show some of Matlab s basic capabilities. Nir Gavish, 2.07 Contents Getting help Matlab development enviroment Variable definitions Mathematical operations

More information

Example. Password generator

Example. Password generator Example Password generator Write a program which generates ten characters as a password. There may be lower-case letters, upper-case letters, and digital characters in the character sequence. Recall that

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

ˆ Note that we often make a trade-off between time and space. ˆ Time complexity ˆ Space complexity. ˆ Unlike time, we can reuse memory.

ˆ Note that we often make a trade-off between time and space. ˆ Time complexity ˆ Space complexity. ˆ Unlike time, we can reuse memory. ˆ We use O-notation to describe the asymptotic 1 upper bound of complexity of the algorithm. ˆ So O-notation is widely used to classify algorithms by how they respond to changes in its input size. 2 ˆ

More information

1 class Lecture6 { 2 3 "Methods" / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 10 / Zheng-Liang Lu Java Programming 185 / 248

1 class Lecture6 { 2 3 Methods / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 10 / Zheng-Liang Lu Java Programming 185 / 248 1 class Lecture6 { 2 3 "Methods" 4 5 } 6 7 / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 10 / Zheng-Liang Lu Java Programming 185 / 248 All roads lead to Rome. Anonymous 但如你根本並無招式, 敵人如何來破你的招式? 風清揚,

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Selections. Zheng-Liang Lu 91 / 120

Selections. Zheng-Liang Lu 91 / 120 Selections ˆ Selection enables us to write programs that make decisions on. ˆ Selection structures contain one or more of the if, else, and elseif statements. ˆ The end statement denotes the end of selection

More information

Recursive Definitions

Recursive Definitions Recursion Objectives Explain the underlying concepts of recursion Examine recursive methods and unravel their processing steps Explain when recursion should and should not be used Demonstrate the use of

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

Two Approaches to Algorithms An Example (1) Iteration (2) Recursion

Two Approaches to Algorithms An Example (1) Iteration (2) Recursion 2. Recursion Algorithm Two Approaches to Algorithms (1) Iteration It exploits while-loop, for-loop, repeat-until etc. Classical, conventional, and general approach (2) Recursion Self-function call It exploits

More information

A Tutorial on Matlab Ch. 3 Programming in Matlab

A Tutorial on Matlab Ch. 3 Programming in Matlab Department of Electrical Engineering University of Arkansas A Tutorial on Matlab Ch. 3 Programming in Matlab Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Plotting M-file Scripts Functions Control Flows Exercises

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window. EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

More information

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

11/2/2017 RECURSION. Chapter 5. Recursive Thinking. Section 5.1

11/2/2017 RECURSION. Chapter 5. Recursive Thinking. Section 5.1 RECURSION Chapter 5 Recursive Thinking Section 5.1 1 Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain kinds of problems that are difficult

More information

Mechanical Engineering Department Second Year (2015)

Mechanical Engineering Department Second Year (2015) Lecture 7: Graphs Basic Plotting MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. This section describes a few of the most

More information

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. PC-MATLAB PRIMER This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. >> 2*3 ans = 6 PCMATLAB uses several lines for the answer, but I ve edited this to save space.

More information

Recursion. Dr. Jürgen Eckerle FS Recursive Functions

Recursion. Dr. Jürgen Eckerle FS Recursive Functions Recursion Dr. Jürgen Eckerle FS 2008 Recursive Functions Recursion, in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

CMSC 132: Object-Oriented Programming II. Recursive Algorithms. Department of Computer Science University of Maryland, College Park

CMSC 132: Object-Oriented Programming II. Recursive Algorithms. Department of Computer Science University of Maryland, College Park CMSC 132: Object-Oriented Programming II Recursive Algorithms Department of Computer Science University of Maryland, College Park Recursion Recursion is a strategy for solving problems A procedure that

More information

Unit-5 Dynamic Programming 2016

Unit-5 Dynamic Programming 2016 5 Dynamic programming Overview, Applications - shortest path in graph, matrix multiplication, travelling salesman problem, Fibonacci Series. 20% 12 Origin: Richard Bellman, 1957 Programming referred to

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Recursion Eng. Anis Nazer First Semester 2016-2017 Recursion Recursion: to define something in terms of itself Example: factorial n!={ 1 n=0 n (n 1)! n>0 Recursion Example:

More information

Programming 1. Script files. help cd Example:

Programming 1. Script files. help cd Example: Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands

More information

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

Peter Hertel. University of Osnabrück, Germany. Lecture presented at APS, Nankai University, China.

Peter Hertel. University of Osnabrück, Germany. Lecture presented at APS, Nankai University, China. s s University of Osnabrück, Germany Lecture presented at APS, Nankai University, China http://www.home.uni-osnabrueck.de/phertel Spring 2012 s Structure your program into Scripts are unnecessary and should

More information

Question Points Score Total 100

Question Points Score Total 100 Name Signature General instructions: You may not ask questions during the test. If you believe that there is something wrong with a question, write down what you think the question is trying to ask and

More information

Evolutionary Algorithms. Workgroup 1

Evolutionary Algorithms. Workgroup 1 The workgroup sessions Evolutionary Algorithms Workgroup Workgroup 1 General The workgroups are given by: Hao Wang - h.wang@liacs.leideuniv.nl - Room 152 Furong Ye - f.ye@liacs.leidenuniv.nl Follow the

More information

Test Bank Ver. 5.0: Data Abstraction and Problem Solving with C++: Walls and Mirrors, 5 th edition, Frank M. Carrano

Test Bank Ver. 5.0: Data Abstraction and Problem Solving with C++: Walls and Mirrors, 5 th edition, Frank M. Carrano Chapter 2 Recursion: The Mirrors Multiple Choice Questions 1. In a recursive solution, the terminates the recursive processing. a) local environment b) pivot item c) base case d) recurrence relation 2.

More information

LECTURE 0: Introduction and Background

LECTURE 0: Introduction and Background 1 LECTURE 0: Introduction and Background September 10, 2012 1 Computational science The role of computational science has become increasingly significant during the last few decades. It has become the

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

BSM510 Numerical Analysis

BSM510 Numerical Analysis BSM510 Numerical Analysis Introduction and Matlab Fundamentals Manar Mohaisen Department of EEC Engineering Lecture Content Introduction to MATLAB 2 Introduction to MATLAB MATLAB 3 Scalars >> x = 5; x

More information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR 603 203 FIRST SEMESTER B.E / B.Tech., (Common to all Branches) QUESTION BANK - GE 6151 COMPUTER PROGRAMMING UNIT I - INTRODUCTION Generation and

More information

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Roger Hansen (rh@fys.uio.no) PGP, University of Oslo September 2004 Introduction to Matlab p.1/22 Contents Programming Philosophy What is Matlab? Example: Linear algebra Example:

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

More information

11. Recursion. n (n 1)!, otherwise. Mathematical Recursion. Recursion in Java: Infinite Recursion. 1, if n 1. n! =

11. Recursion. n (n 1)!, otherwise. Mathematical Recursion. Recursion in Java: Infinite Recursion. 1, if n 1. n! = Mathematical Recursion 11. Recursion Mathematical Recursion, Termination, Call Stack, Examples, Recursion vs. Iteration, Lindenmayer Systems Many mathematical functions can be naturally defined recursively.

More information

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab Overview Lecture 13: Graphics and Visualisation Graphics & Visualisation 2D plotting 1. Plots for one or multiple sets of data, logarithmic scale plots 2. Axis control & Annotation 3. Other forms of 2D

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms: Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

More information

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

12. Recursion. n (n 1)!, otherwise. Educational Objectives. Mathematical Recursion. Recursion in Java: 1, if n 1. n! =

12. Recursion. n (n 1)!, otherwise. Educational Objectives. Mathematical Recursion. Recursion in Java: 1, if n 1. n! = Educational Objectives You understand how a solution to a recursive problem can be implemented in Java. You understand how methods are being executed in an execution stack. 12. Recursion Mathematical Recursion,

More information

User-Defined Function

User-Defined Function ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider

More information

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

C++ Programming Lecture 1 Software Engineering Group

C++ Programming Lecture 1 Software Engineering Group C++ Programming Lecture 1 Software Engineering Group Philipp D. Schubert Contents 1. More on data types 2. Expressions 3. Const & Constexpr 4. Statements 5. Control flow 6. Recap More on datatypes: build-in

More information

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont. Announcements CS43: Discrete Structures Strong Induction and Recursively Defined Structures Işıl Dillig Homework 4 is due today Homework 5 is out today Covers induction (last lecture, this lecture, and

More information

4 Visualization and. Approximation

4 Visualization and. Approximation 4 Visualization and Approximation b A slope field for the differential equation y tan(x + y) tan(x) tan(y). It is not always possible to write down an explicit formula for the solution to a differential

More information

Dynamic Programming. An Introduction to DP

Dynamic Programming. An Introduction to DP Dynamic Programming An Introduction to DP Dynamic Programming? A programming technique Solve a problem by breaking into smaller subproblems Similar to recursion with memoisation Usefulness: Efficiency

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

Formal languages and computation models

Formal languages and computation models Formal languages and computation models Guy Perrier Bibliography John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman - Introduction to Automata Theory, Languages, and Computation - Addison Wesley, 2006.

More information

Lecture 14. Xiaoguang Wang. March 11th, 2014 STAT 598W. (STAT 598W) Lecture 14 1 / 36

Lecture 14. Xiaoguang Wang. March 11th, 2014 STAT 598W. (STAT 598W) Lecture 14 1 / 36 Lecture 14 Xiaoguang Wang STAT 598W March 11th, 2014 (STAT 598W) Lecture 14 1 / 36 Outline 1 Some other terms: Namespace and Input/Output 2 Armadillo C++ 3 Application (STAT 598W) Lecture 14 2 / 36 Outline

More information

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar

More information

1 Elementary number theory

1 Elementary number theory Math 215 - Introduction to Advanced Mathematics Spring 2019 1 Elementary number theory We assume the existence of the natural numbers and the integers N = {1, 2, 3,...} Z = {..., 3, 2, 1, 0, 1, 2, 3,...},

More information

Arithmetic Compound Assignment Operators

Arithmetic Compound Assignment Operators Arithmetic Compound Assignment Operators Note that these shorthand operators are not available in languages such as Matlab and R. Zheng-Liang Lu Java Programming 76 / 141 Example 1... 2 int x = 1; 3 System.out.println(x);

More information

Variables and Assignments

Variables and Assignments Variables and Assignments ˆ A variable is used to keep a value or values. ˆ A box which contains something. ˆ In most languages, a statement looks like var = expression, where var is a variable and expression

More information

1. Register an account on: using your Oxford address

1. Register an account on:   using your Oxford  address 1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation

More information

Arrays. ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be

Arrays. ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be Arrays ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be ˆ row vectors: u R 1 n for any positive integer n ˆ

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

Discussion on Writing of Recursive Algorithm

Discussion on Writing of Recursive Algorithm , pp.127-134 http://dx.doi.org/10.14257/ijhit.2013.6.6.11 Discussion on Writing of Recursive Algorithm Song Jinping Computer Department, Jining Teachers College, Wulanchabu, China jnsongjinping@126.com

More information

APPM 2460: Week Three For, While and If s

APPM 2460: Week Three For, While and If s APPM 2460: Week Three For, While and If s 1 Introduction Today we will learn a little more about programming. This time we will learn how to use for loops, while loops and if statements. 2 The For Loop

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

Symbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is

More information

APCS-AB: Java. Recursion in Java December 12, week14 1

APCS-AB: Java. Recursion in Java December 12, week14 1 APCS-AB: Java Recursion in Java December 12, 2005 week14 1 Check point Double Linked List - extra project grade Must turn in today MBCS - Chapter 1 Installation Exercises Analysis Questions week14 2 Scheme

More information

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD Introduction to MATLAB for Numerical Analysis and Mathematical Modeling Selis Önel, PhD Advantages over other programs Contains large number of functions that access numerical libraries (LINPACK, EISPACK)

More information

Induction and Recursion. CMPS/MATH 2170: Discrete Mathematics

Induction and Recursion. CMPS/MATH 2170: Discrete Mathematics Induction and Recursion CMPS/MATH 2170: Discrete Mathematics Outline Mathematical induction (5.1) Sequences and Summations (2.4) Strong induction (5.2) Recursive definitions (5.3) Recurrence Relations

More information

INTRODUCTION. Objective: - Algorithms - Techniques - Analysis. Algorithms:

INTRODUCTION. Objective: - Algorithms - Techniques - Analysis. Algorithms: INTRODUCTION Objective: - Algorithms - Techniques - Analysis. Algorithms: Definition: Pseudocode: An algorithm is a sequence of computational steps that tae some value, or set of values, as input and produce

More information

ECE 202 LAB 3 ADVANCED MATLAB

ECE 202 LAB 3 ADVANCED MATLAB Version 1.2 1 of 13 BEFORE YOU BEGIN PREREQUISITE LABS ECE 201 Labs EXPECTED KNOWLEDGE ECE 202 LAB 3 ADVANCED MATLAB Understanding of the Laplace transform and transfer functions EQUIPMENT Intel PC with

More information

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

More information

Getting Started with MATLAB

Getting Started with MATLAB Getting Started with MATLAB Math 315, Fall 2003 Matlab is an interactive system for numerical computations. It is widely used in universities and industry, and has many advantages over languages such as

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45

More information

TOPIC 6 Computer application for drawing 2D Graph

TOPIC 6 Computer application for drawing 2D Graph YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM TOPIC 6 Computer application for drawing 2D Graph Plotting Elementary Functions Suppose we wish

More information

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1 INC151 Electrical Engineering Software Practice MATLAB Graphics Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1 Graphical display is one of MATLAB s greatest strengths and most

More information